def prost(x):
    ans = True
    if len(str(x)) != 3:
        ans = False
    for d in range(2, int(x ** 0.5) + 1):
        if x % d == 0:
            ans = False
    return ans


dig = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}
n = input().split()
if len(n) != 3 or not (set(n) <= set(dig.keys())):
    print("Wrong input")
    exit()

n = dig[n[0]] * 100 + dig[n[1]] * 10 + dig[n[2]]
if 100 > n <= 1000:
    print("Wrong input")
    exit()
if prost(n):
    print(n)
else:
    pr = n
    while not prost(pr):
        pr += 1
    pl = n
    while not prost(pl):
        pl -= 1
    if abs(n - pr) >= abs(n - pl):
        print(pl)
    else:
        print(pr)
